package utils

import (
	"emicro_test/emicro_8/grpc_server/mail/common"
	"gopkg.in/gomail.v2"
	)

func SendMail(toMail string, body string) error{
	smtp_addr := common.Config.String("smtp_addr")
	smtp_port, _ := common.Config.Int("smtp_port")
	smtp_user := common.Config.String("smtp_user")
	smtp_pwd := common.Config.String("smtp_password")
	m := gomail.NewMessage()
	m.SetHeader("From", smtp_user)
	m.SetHeader("To", toMail)
	m.SetBody("text/plain", body)
	d := gomail.NewPlainDialer(smtp_addr, smtp_port, smtp_user, smtp_pwd)
	if err := d.DialAndSend(m); err != nil {
		return err
	}
	return nil
}
